//
//  menu.cpp
//  airfight
//
//  Created by aaron more on 12-8-20.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include <iostream>

#include "MenuLayer.h"
#include "../resources.h"
#include "BaseContructionLayer.h"
#include "FighterUpgradeLayer.h"
#include "SearchPlayerLayer.h"
#include "BattleLoadingLayer.h"
#include "AboutLayer.h"

MenuLayer::MenuLayer()
{
}

MenuLayer::~MenuLayer()
{
}

bool MenuLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSprite *background = CCSprite::create("images/cover.png");
    background->setPosition(ccp(160, 240));
    addChild(background);
    
    CCMenuItemFont::setFontSize(18);
    
    CCMenuItemFont *aboutMenuItem = CCMenuItemFont::itemWithString("关于", this, menu_selector(MenuLayer::aboutCallback));
    aboutMenuItem->setPosition(ccp(280, 450));
    
    CCMenuItemFont::setFontSize(25);
    
    CCMenuItemFont *contructionMenuItem = CCMenuItemFont::itemWithString("基地建设", this, menu_selector(MenuLayer::contructionCallback));
    contructionMenuItem->setPosition(ccp(160, 350));
    
    CCMenuItemFont *upgradeMenuItem = CCMenuItemFont::itemWithString("战机升级", this, menu_selector(MenuLayer::upgradeCallback));
    upgradeMenuItem->setPosition(ccp(160, 300));
    
    CCMenuItemFont *searchMenuItem = CCMenuItemFont::itemWithString("寻找对手", this, menu_selector(MenuLayer::searchCallback));
    searchMenuItem->setPosition(ccp(160, 250));
    
    CCMenuItemFont::setFontSize(30);
    
    CCMenuItemFont *startMenuItem = CCMenuItemFont::itemWithString("直接开战", this, menu_selector(MenuLayer::startCallback));
    startMenuItem->setPosition(ccp(160, 190));
    
    CCMenu *menu = CCMenu::menuWithItems(aboutMenuItem, contructionMenuItem, upgradeMenuItem, searchMenuItem, startMenuItem, NULL);
    menu->setPosition(CCPointZero);
    addChild(menu);
    
    return true;
}

void MenuLayer::aboutCallback()
{
    CCScene *scene = CCScene::create();
    CCLayer *aboutLayer = AboutLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(aboutLayer);
    layer->m_bIsRunning = true;
    scene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(scene);
}

void MenuLayer::contructionCallback()
{
    CCScene *scene = CCScene::create();
    CCLayer *baseContructionLayer = BaseContructionLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(baseContructionLayer);
    layer->m_bIsRunning = true;
    scene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(scene);
}

void MenuLayer::upgradeCallback()
{
    CCScene *scene = CCScene::create();
    CCLayer *fighterUpgradeLayer = FighterUpgradeLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(fighterUpgradeLayer);
    layer->m_bIsRunning = true;
    scene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(scene);
}

void MenuLayer::searchCallback()
{
    CCScene *scene = CCScene::create();
    CCLayer *searchPlayerLayer = SearchPlayerLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(searchPlayerLayer);
    layer->m_bIsRunning = true;
    scene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(scene);
}

void MenuLayer::startCallback()
{
    CCScene *scene = CCScene::create();
    CCLayer *loadingLayer = BattleLoadingLayer::create();
    CCLayerMultiplex* layer = CCLayerMultiplex::createWithLayer(loadingLayer);
    layer->m_bIsRunning = true;
    scene->addChild(layer, 0);
    CCDirector::sharedDirector()->replaceScene(scene);
}
